package com.weiaibenpao.demo.chislim.presenter;

import com.orhanobut.logger.Logger;
import com.weiaibenpao.demo.chislim.base.BasePresenter;
import com.weiaibenpao.demo.chislim.bean.UserBean;
import com.weiaibenpao.demo.chislim.bean.UserDataBean;
import com.weiaibenpao.demo.chislim.retrofit.RetrofitUtils;
import com.weiaibenpao.demo.chislim.retrofit.rx.LoadingTransformer;
import com.weiaibenpao.demo.chislim.retrofit.rx.NetWorkTransformer;
import com.weiaibenpao.demo.chislim.retrofit.rx.SimpleObserver;
import com.weiaibenpao.demo.chislim.view.LoginView;

/**
 * Created by lenovo on 2017/12/27.
 */
public class LoginPresenter extends BasePresenter<LoginView> {
    public void loginByPhone(String userPhone,String securityCode,String registerId,String phoneModel) {
        RetrofitUtils.getAPIService().login(userPhone,securityCode,registerId,phoneModel).
                compose(new NetWorkTransformer<UserDataBean>()).
                compose(new LoadingTransformer<UserDataBean>(mContext)).
                subscribe(new SimpleObserver<UserDataBean>(mCompositeDisposable) {
                    @Override
                    public void call(UserDataBean userDataBean) {
                        getView().loginSuccess(userDataBean);
                    }


                });
    }

    public void loginByThree(String openId,String registerSource,String registerId,String phoneModel) {
        RetrofitUtils.getAPIService().loginThree(openId,registerSource,registerId,phoneModel).
                compose(new NetWorkTransformer<UserDataBean>()).
                compose(new LoadingTransformer<UserDataBean>(mContext)).
                subscribe(new SimpleObserver<UserDataBean>(mCompositeDisposable) {
                    @Override
                    public void call(UserDataBean userDataBean) {
                        getView().loginSuccess(userDataBean);
                    }


                });
    }
    /**
     * 绑定手机号
     */
    public void bindingPhone(String userImage,String userName,String openId,String registerSource,String userPhone,String securityCode,String phoneModel) {
        RetrofitUtils.getAPIService().bindingPhone(userImage,userName,openId,registerSource,userPhone,securityCode,phoneModel).
                compose(new NetWorkTransformer<UserDataBean>()).
                compose(new LoadingTransformer<UserDataBean>(mContext)).
                subscribe(new SimpleObserver<UserDataBean>(mCompositeDisposable) {
                    @Override
                    public void call(UserDataBean userDataBean) {
                        getView().loginSuccess(userDataBean);
                    }


                });
    }
    public void getSeedCode(String userPhone) {
        Logger.e("getSeedCode--->"+userPhone);
        RetrofitUtils.getAPIService().seedCode(userPhone).
                compose(new NetWorkTransformer()).
                compose(new LoadingTransformer(mContext)).
                subscribe(new SimpleObserver(mCompositeDisposable) {
                    @Override
                    public void call(Object object) {
                        getView().seedSuccess("发送成功");
                    }

                });
    }

    public void upDataInfo(int userId, String userImage, String userName, String userSex, int userHeight, float userWeight, String userBirth, String userSign) {
        RetrofitUtils.getAPIService().updDataInfo(userId, userImage, userName, userSex, userHeight, userWeight, userBirth, userSign,"").
                compose(new NetWorkTransformer<UserBean>()).
                compose(new LoadingTransformer<UserBean>(mContext)).
                subscribe(new SimpleObserver<UserBean>(mCompositeDisposable) {
                    @Override
                    public void call(UserBean userBean) {
                        getView().upDataInfoSuccess(userBean);
                    }


                });
    }

    /**
     * 修改手机号码
     * @param userId
     */
//    public void upDataPhone(int userId, String userPhone, String code) {
//        RetrofitUtils.getAPIService().updateUserPhone(userId, userPhone, code).
//                compose(new NetWorkTransformer<UserBean>()).
//                compose(new LoadingTransformer<UserBean>(mContext)).
//                subscribe(new SimpleObserver<UserBean>(mCompositeDisposable) {
//                    @Override
//                    public void call(UserBean userBean) {
//                        getView().upDataInfoSuccess(userBean);
//                    }
//
//                    @Override
//                    public void showErrorMsg(String message) {
//                    }
//                });
//    }
}
